#!/usr/bin/env python
#coding: ISO-8859-1 -*-'

__author__ = 'Ralf Schoenian'

import os
from subprocess import Popen, PIPE
import sys

testpath = os.path.dirname(os.path.abspath(__file__))
workpath = testpath.replace('/test','')
sys.path.append(workpath)

import model

'''
This module contains functions to deal with the test.db
'''

CAT = '/bin/cat'
DB = model.config.get('Settings','dbfile')
SQLite = '/usr/bin/sqlite3 '

def run_sql(sqlFile):
    '''Runs sql from the given sqlFile. '''

    cmd = create_sql(sqlFile)
    result  = Popen(cmd, stdout=PIPE, shell=True).stdout.read()
    result = result.strip()
    return result

def create_sql(sqlFile):
    '''Returns string to execute a sql file.'''
    cmd = '%s %s | %s %s' % (CAT, sqlFile, SQLite, DB)
    return cmd